package com.googlecode.stockhamster.bank;


public class BankFunc {
	
	final static long TIME_LIMIT = 7 * 24 * 3600 * 1000;
	final static char dvCode = '#';
	
	final static char[] dic = {
			'A','B','C','D','E','F','G','H','I','J','K','L',
			'M','N','P','Q','R','S','T','U','V','W','X','Y',
			'Z','a','b','c','d','e','f','g','h','i','j','k',
			'l','m','n','p','q','r','s','t','u','v','w','x',
			'y','z','0','1','2','3','4','5','6','7','8','9'
			};
	final static int rate = 60;//dic.length;

	static String transform (long num){
		int count = 0;
		long tlimit = TIME_LIMIT;
		String res = "";
		num %= tlimit;
		while (tlimit > 0){
			tlimit /= rate;
			count ++;
		}
		while (num > 0){
			res += dic[(int)(num % rate)]; 
			num /= rate;
		}
		while (res.length() < count)
			res += res + dic[0];
		return res;
	}
	
	static String genCode (int digits){
		Double ran;
		String code = "";
		String tcheck = transform(System.currentTimeMillis());
		for (int i = 0; i < digits - tcheck.length(); i++){
			ran = Math.random() * 10000;
			code += dic[(int)(ran.intValue() % rate)];
		};
		return code + tcheck;
	}
	
	static String genMoneyCode(int digits, long amount){
		return amount + dvCode + genCode(digits - String.valueOf(amount).length() - 1);
	}

}
